package org.thesis.adapter;

import java.util.List;

import org.thesis.doituong.attach;


import org.thesis.R;
import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class attach_adapter extends ArrayAdapter<attach>
{
	Activity context;
	List<attach>list;
	String tag = "att_apdater";
	
	public attach_adapter(Activity context, List<attach>list)
	{
		super(context,R.layout.row_attach_layout,list);
		this.context = context;
		this.list = list;
		Log.v(tag, "contructor");
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = null;
		if(convertView == null)
		{
			LayoutInflater li = context.getLayoutInflater();
			v = li.inflate(R.layout.row_attach_layout, null);
		}
		else
		{
			v = convertView;
		}
		
		final attach att = list.get(position);
		TextView tv = (TextView)v.findViewById(R.id.tv_row_att);
		CheckBox cb = (CheckBox)v.findViewById(R.id.cb_row_att);
		cb.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CheckBox cb_temp = (CheckBox)v.findViewById(R.id.cb_row_att);
				if(cb_temp.isChecked())
					att.setCheck(true);
				else
					att.setCheck(false);
				
			}
		});
		
		tv.setText(att.getStr_attach());
		cb.setChecked(att.isCheck());
		return v;
	}

}
